package com.cuit.ocp.service.impl;

import com.cuit.ocp.bean.Order;
import com.cuit.ocp.bean.ReturnOrder;
import com.cuit.ocp.dao.ReturnOrderDao;
import com.cuit.ocp.service.ReturnOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReturnOrderServicelmpl implements ReturnOrderService {
    @Resource
    ReturnOrderDao returnOrderDao;

    public Map<Object,Object> getAllReturnOrderByPage(int current_page){
        PageHelper.startPage(current_page,5);
        List<ReturnOrder> list = returnOrderDao.selectAllReturnOrderByPage();
        PageInfo <ReturnOrder> pageInfo = new PageInfo<>(list);
        Map <Object, Object> map = new HashMap<>();
        map.put("total", pageInfo.getTotal());
        map.put("rows", pageInfo.getList());
//        System.out.println(pageInfo.getList());
//        map.put("总条数", pageInfo.getTotal());
//        map.put("总页数", pageInfo.getPages());
//        map.put("当前页数",pageInfo.getPageNum());
//        map.put("每页显示条数",pageInfo.getPageSize());
//        map.put("是否第一页",pageInfo.isIsFirstPage());
//        map.put("是否最后一页",pageInfo.isIsLastPage());
//        map.put("查出的所有退货订单",list);
        return map;
    }

    public Map <String, String> addReturnOrder(ReturnOrder returnOrder){

        Map <String, String> map = new HashMap <>();
        if (returnOrderDao.addReturnOrder(returnOrder) == 1) {
            map.put("flag", "1");
            map.put("message", "添加成功！");
        } else {
            map.put("flag", "2");
            map.put("message", "添加失败！");
        }
        return map;
    }

    public Map<String,String> deleteReturnOrder(int re_id){
        Map <String, String> map = new HashMap <>();
        if(returnOrderDao.deleteReturnOrderById(re_id)==1){
            map.put("flag", "1");
            map.put("message", "删除成功！");
        }else {
            map.put("flag", "2");
            map.put("message", "删除失败！");
        }
        return map;
    }

    public Map<String,Object> selectReturnOrderById(int re_id){
        Map <String, Object> map = new HashMap <>();
        if(returnOrderDao.selectReturnOrderById(re_id)!=null){
            map.put("flag", "1");
            map.put("message", "查询成功！");
            map.put("row",returnOrderDao.selectReturnOrderById(re_id));
        }else {
            map.put("flag", "2");
            map.put("message", "查询失败！");
        }
        return map;
    }

    public Map<String,String> updateReturnOrderById(ReturnOrder returnOrder){
        Map <String, String> map = new HashMap <>();
        if(returnOrderDao.updateReturnOrderById(returnOrder)==1){
            map.put("flag", "1");
            map.put("message", "更新成功！");
        }else {
            map.put("flag", "2");
            map.put("message", "更新失败！");
        }
        return map;
    }

    public Map<String,Object> selectReturnOrderByName(String order_name){
        Map <String, Object> map = new HashMap <>();
        List<ReturnOrder> orders = returnOrderDao.selectReturnOrderByName(order_name);
        if(orders.size() > 0) {
            //map.put("flag", "1");
            map.put("message", "查询成功！");
            map.put("row",orders);
        }else {
            //map.put("flag", "2");
            map.put("message", "无查询结果！");
        }
        return map;
    }
}
